package com.huifai;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

/**
 * <br>==========================
 * <br> 开发：jerry
 * <br> 创建时间：2019-07-15 下午2:13
 * <br> 版本：1.0
 * <br> 描述：应用启动入口
 * <br>==========================
 */
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public class UimsApplication {

	public static void main(String[] args) {
		SpringApplication.run(UimsApplication.class,args);
	}

	private CorsConfiguration buildConfig() {
		CorsConfiguration corsConfiguration = new CorsConfiguration();
		corsConfiguration.addAllowedOrigin("*"); // 1
		corsConfiguration.addAllowedHeader("*"); // 2
		corsConfiguration.addAllowedMethod("*"); // 3
		corsConfiguration.setAllowCredentials(true);
		return corsConfiguration;
	}


	@Bean
	public CorsFilter corsFilter() {
		UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
		source.registerCorsConfiguration("/**", buildConfig()); // 4
		return new CorsFilter(source);
	}

}
